package com.cy.controller;

import com.cy.captcha.*;
import com.cy.captcha.factory.CaptchaFactory;
import com.cy.captcha.factory.ICaptchaFactory;
import com.cy.captcha.factory.impl.AbstractCaptcha;
import com.cy.captcha.param.CaptchaBaseParam;
import com.cy.captcha.vo.CaptchaBaseVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author stx
 * @date 2018/11/5 14:58
 * @desc
 */
@Controller
public class CaptchaController {

    @RequestMapping("/blockPuzzle")
    @ResponseBody
    R blockPuzzle() {

        ICaptchaFactory captchaFactory = new CaptchaFactory();
        AbstractCaptcha captcha = captchaFactory.getInstance(CaptchaType.BLOCK_PUZZLE);
        CaptchaBaseParam captchaBaseParam = new CaptchaBaseParam();
        captchaBaseParam.setUrlOrPath(ImageUtils.getBlockPuzzleBgPath());
        captcha.setJigsawUrlOrPath(ImageUtils.getBlockPuzzleJigsawPath());
        CaptchaBaseVO dataVO = captcha.create(captchaBaseParam);
        R r = new R();
        return r.put("dt", dataVO);
    }

    @RequestMapping("/clickWord")
    @ResponseBody
    R clickWord() {

        ICaptchaFactory captchaFactory = new CaptchaFactory();
        AbstractCaptcha captcha = captchaFactory.getInstance(CaptchaType.CLICK_WORD);

        CaptchaBaseParam captchaBaseParam = new CaptchaBaseParam();
        captchaBaseParam.setUrlOrPath(ImageUtils.getClickWordBgPath());
        captcha.setFontColorRandom(false);
        CaptchaBaseVO dataVO = captcha.create(captchaBaseParam);
        R r = new R();
        return r.put("dt", dataVO);
    }


}
